<?php
	class index_diyControl extends skymvc{
		
		public function __construct(){
			parent::__construct();
		} 
		
		public function onDefault(){
			//新鲜事
	    	$newslist=$this->news();
	    	$this->smarty->assign(array(
	    		"newslist"=>$newslist
	    	));
	    	//论坛
	    	$forumlist=C("forumapi")->recommend(0,6);
	    	$this->smarty->assign(array(
	    		"forumlist"=>$forumlist
	    	));
	    	$this->smarty->display("index_diy/index.html");
	    	 
		}
		
		 public function news(){
			$start=get('per_page','i');
			$limit=24;
			$userid=M("login")->userid;
			$where=" status=0 AND fromid=0 AND siteid=".SITEID;
			$order="newsid DESC";
			$rscount=true;
			$url="/index.php?m=news&a=school";
			$option=array(
				"where"=>$where,
				"start"=>$start,
				"limit"=>$limit,
				"order"=>$order
			);
			$data=M("news")->select($option,$rscount);
			
			if($data){
				foreach($data as $v){
					$uids[]=$v['userid'];
				}
				$us=M("user")->getUserByIds($uids); 
				//获取关注的人
				if($userid){
					$fuids=M("follow")->selectCols(array(
						"fields"=>"t_userid",
						"where"=>" userid=".$userid." AND t_userid in("._implode($uids).")"
					));
					if(!$fuids) $fuids=array($userid); 
				}
				
				foreach($data as $k=>$v){
					if($v['imgsdata']){
							$v['imgsdata']=explode(",",$v['imgsdata']);
						}else{
							$v['imgsdata']="";
					}
					if($fuids && in_array($v['userid'],$fuids)){
						$v['isfollow']=1;
					}else{
						$v['isfollow']=0;
					} 
					$v['nickname']=$us[$v['userid']]['nickname'];
					$v['user_head']=$us[$v['userid']]['user_head'];		
					$v['zans']=M("news_love")->newlist($v['newsid']);
					$v['cms']=M("news_comment")->newlist($v['newsid']);
					$data[$k]=$v;
				}
			}
			return $data; 
		}
	}
?>